package com.thinkgem.jeesite.modules.sys.security;

import com.thinkgem.jeesite.modules.sys.SysConstants;
import com.thinkgem.jeesite.modules.sys.utils.PasswordUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

/**
 * @Author:Kongxiangsheng
 * @DesCription:
 * @Date:Created in 15:42 2018/7/16
 * @Modified By:
 */
public class MyHashedCredentialsMatcher extends HashedCredentialsMatcher {
    public MyHashedCredentialsMatcher(String hashAlgorithmName) {
        super(hashAlgorithmName);
    }

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        // 如果是免密码登录,则直接返回true
        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
        if (upToken.getLoginType().equals(PasswordUtils.LOGIN_TYPE_NOPASSWORD)) {
            return true;
        }
        // 否则走正常校验逻辑
        return super.doCredentialsMatch(token, info);
    }
}
